module.exports = function initProjectPage() {
	let {
		projectComp,
	} = $['components-jq']
	projectComp.dataGrid = $("#main-tabs-project")
	projectComp.formDialog = $("#project-form-dialog")
	projectComp.form = $("#project-form")
	projectComp.formName = $("#project-form-name")
	projectComp.formDesc = $("#project-form-desc")
	projectComp.formServerUrl = $("#project-form-serverurl")
	projectComp.formTeam = $("#project-form-team")
	projectComp.formBtnSave = $("#project-form-btn-save")
	projectComp.formBtnCancel = $("#project-form-btn-cancel")

	initDailog(projectComp)
	initDataGrid(projectComp)
}

function initDailog(projectComp) {
	let {
		formDialog,
		form,
		formName,
		formDesc,
		formServerUrl,
		formTeam,
		formBtnSave,
		formBtnCancel,
	} = projectComp
	formBtnSave.linkbutton({
		text: '保存',
		iconCls: 'icon-save',
		onClick() {
			formDialog.dialog('close')
		},
	})
	formBtnCancel.linkbutton({
		text: '取消',
		iconCls: 'icon-cancel',
		onClick() {
			form.form('clear')
			formDialog.dialog('close')
		},
	})

	// {
	// 	iconCls: 'icon-save',
	// 	resizable:true,
	// 	modal: true,
	// 	closed: true,
	// }
}

function initDataGrid(projectComp) {
	let {
		dataGrid,
		formDialog,
	} = projectComp
	dataGrid.datagrid({
		fit: true,
		fitColumns: true,
		rownumbers: true,
		singleSelect: true,
		scrollOnSelect: true,
		toolbar: [{
			iconCls: 'icon-add',
			text: '新建',
			handler() {
				formDialog.dialog('open')
			}
		}, '-', {
			iconCls: 'icon-edit',
			text: '修改',
			handler() {
				console.log(this)
				alert('help')
			}
		}, '-', {
			iconCls: 'icon-remove',
			text: '删除',
			handler() {
				alert('help')
			}
		}],
		columns: [
			[{
				field: 'id',
				title: 'ID',
				width: 50,
			}, {
				field: 'name',
				title: '项目名',
				width: 80
			}, {
				field: 'create',
				title: '创建时间',
				width: 100,
			}, {
				field: 'modify',
				title: '修改时间',
				width: 100,
			}, {
				field: 'team',
				title: '所属团队',
				width: 100,
			}, {
				field: 'desc',
				title: '描述',
				width: 100,
			}]
		],
		data: [{
			name: 'xxx',
			code: 'xxx',
			price: 2,
		}, {
			name: 'xxx',
			code: 'xxx',
			price: 2,
		}, {
			name: 'xxx',
			code: 'xxx',
			price: 2,
		}]
	});
}